<?php
    class Home_m extends Model{
        function Home_m(){
            parent::Model();
            $this->load->database();
        }
        function login($name,$pass){
            $query = $this->db->get_where('user', array('username'=>$name, 'password'=>$pass));
            return $query;          
        }    
        function register($data){  
            $query = $this->db->insert('user',$data);
            return $query;                
        }

        function get_username($username){
            $query = $this->db->get_where('user', array('username' => $username));
            return $query;
        }

        function get_email($email){
            $query = $this->db->get_where('user', array('email' => $email));
            return $query;
        }

        function check_old_password($id,$pass){
            $query = $this->db->get_where('user', array('user_id'=>$id, 'password'=>$pass));
            return $query;          
        }    

        function get_user_id_max(){
            $this->db->select_max('user_id', 'max_id');
            $query = $this->db->get('user');
            return $query;
        }

        function get_user_profie($userid){
            $query = $this->db->get_where('user', array('user_id' => $userid));
            return $query;
        }

        function change_user_profile($data, $id){
            $query=  $this->db->update('user',$data,array('user_id'=>$id));
            return $query;

        }
        function get_setting_info($setting_name){
            $this->db->from('site_settings');
            $this->db->where(array('setting_name'=>$setting_name));
            $query = $this->db->get();
            return $query;
        }
        
        function list_news(){
            $this->db->from('news');
            $this->db->order_by("id", "desc");
            $this->db->limit(2);
            $query=$this->db->get();
            return $query->result_array();
        }
        function get_news_by_id($id){
            $query = $this->db->get_where('news',array('id'=>$id));
            return $query;
        }
        function add_comment($data){
            $query = $this->db->insert('comment_news',$data);
            return $query;                
        }
        function list_comment(){
            $this->db->select();
            $this->db->from('comment_news');
            $this->db->where('is_accepted', 1);
            $this->db->order_by('id','ASC');
            $query = $this->db->get();
            return $query->result_array();    
        }
    }
?>
